<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_man_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_user($data){
		$this->db->insert('USERS',$data);
	}
	
	function get_user_man_grid(){	
		$this->db->select('*');
		$this->db->from('USERS');
		$this->db->join('ROLE','ROLE.IDROLE = USERS.IDROLE');
		$this->db->where("USERS.STATUS > 0 ");
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('USERS');
		$this->db->join('ROLE','ROLE.IDROLE = USERS.IDROLE');
		$this->db->where("USERS.STATUS > 0 ");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function delete_user($id_user){
		$data = array(
			'STATUS' 			=> 0
		);
		$this->db->where('ID_USER',$id_user);
		$this->db->update('USERS',$data);
	}
	
	function get_userID($id_user){
		$this->db->select('*');
		$this->db->from('USERS');
		$this->db->join('ROLE','ROLE.IDROLE = USERS.IDROLE');
		$this->db->where('ID_USER',$id_user);
		$query = $this->db->get();
		return $query;
	}
	
	function get_role(){
		$this->db->select("*");
		$this->db->from('ROLE');
		$this->db->where("STATUS > 0 ");
		$this->db->order_by('IDROLE');
		$query = $this->db->get();
		return $query;
	}
	
	function update_user($data,$id_user){
		$this->db->where('ID_USER',$id_user);
		$this->db->update('USERS',$data);
	}
	
	function get_user(){
		$this->db->select("*");
		$this->db->from('USERS');
		$this->db->where("STATUS > 0 ");
		$query = $this->db->get();
		return $query;
	}
	
}

?>